// Copyright 2007-2010 Comdiv (F. Sadykov) - http://code.google.com/u/fagim.sadykov/
// Supported by Media Technology LTD 
//  
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// 
// MODIFICATIONS HAVE BEEN MADE TO THIS FILE
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Comdiv.Extensions;
using Comdiv.QueryEngine;

namespace Comdiv.Doc{
    public class DocumentQuery : Query<object, DocumentQueryContext, DocumentQuery>{
        private readonly IList<AssemblyDescriptor> _libs = new List<AssemblyDescriptor>();
        private readonly IDictionary<string, string> _namespacePages = new Dictionary<string, string>();

        private readonly IDictionary<string, IList<TypeDescriptor>> _types =
            new Dictionary<string, IList<TypeDescriptor>>();

        public string[] ExcludePatterns;
        public string[] IncludePatterns;

        public string IndexPage;
        public string InputDirectory;
        public string OutputDirectory;
        public string ViewDirectory;

        public IList<AssemblyDescriptor> Libs{
            get { return _libs; }
        }

         public TypeDescriptor this[Type type]{
            get{
                if(!this.Types.ContainsKey(type.Namespace)){
                    return null;
                }
                return this.Types[type.Namespace].FirstOrDefault(x => x.Type == type);
            }
        }

        private IList<Type> configuredTypes = new List<Type>();

        public IDictionary<string, IList<TypeDescriptor>> Types{
            get { return _types; }
        }

        public IDictionary<string, string> NamespacePages{
            get { return _namespacePages; }
        }

        public IList<Type> ConfiguredTypes{
            get { return configuredTypes; }
        }

        protected override void postToString(TextWriter writer){
            writer.WriteLine("input: " + (InputDirectory ?? ""));
            writer.WriteLine("output: " + (OutputDirectory ?? ""));
            writer.WriteLine("views: " + (ViewDirectory ?? ""));
            writer.WriteLine("exclude: " + (ExcludePatterns ?? new string[]{}).concat("; "));
            writer.WriteLine("include: " + (IncludePatterns ?? new string[]{}).concat("; "));
        }
    }
}